<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/7
 * Time: 18:25
 */
namespace  Admin\Controller;
 use Admin\Model\InspectionContentChangeModel;
 use Admin\Model\InspectiondetailinfoModel;
 use Admin\Model\InspectionIndexModel;
 use Admin\Model\InspectioninfoModel;
 use Admin\Model\InspectioniteminfoModel;
 use  Base\Controller\CurdController;
class  InspectionContentController extends  CurdController{

    public function __construct()
    {
        parent::__construct(true, true);
    }
    public  function  getAll()
    {
        if($_REQUEST['keyword']){
            $map['name'] = array('like','%'.$_REQUEST['keyword'].'%');
            $map['description']  = array('like', '%'.$_REQUEST['keyword'].'%');
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
        }
        if(I('get.typeid')){
            $where['typeid']=I('get.typeid');
        }
        if($_REQUEST['selects']){
            $limit=$_REQUEST['selects'];
        }else{
            $limit=20;
        }
        $where['status']=array('EGT','0');
        $data = $this->model ->pageToView($limit, true,$where);
//       dump($data);
        $this->assign("page", $data['page']);
        $this->assign("list", $data['list']);
    }
    /**
     *化验单详情编辑
     */
    public  function  editcontent(){
         $data['itemvalue']=$_REQUEST['itemvalue'];
         $data['id']=$_REQUEST['id'];
         $data['paramvalue']=$_REQUEST['paramvalue'];
         $result  =   $this->model->save($data);
        if($result){
            $dataes['status']=1;
            $this->changecontent($data['id']);
            $this->ajaxReturn($dataes);
         }else{
            $dataes['status']=0;
            $this->ajaxReturn($dataes);
        }
    }

    /**
     * 数据录入分析
     */
    public  function changecontent($id){
         $InspectionContentChangeModel=new InspectionContentChangeModel();
        $contentinfo=$this->model->where('id='.$id)->relation(true)->find();
        $data['indexid']=$contentinfo['indexid'];
        $data['inspectioncontentid']=$contentinfo['itemid'];
        $data['userid']=$this->user['id'];
        $userinfo=$this->getUser($this->user['id']);
        $data['content']='化验单录入员'.$userinfo['name'].'给'.$contentinfo['inspectioninfo']['name'].'下面的'.$contentinfo['inspectioniteminfo']['name'].'录入数据';
        $InspectionContentChangeModel->add($data);
    }
}